<template>
  <div class="pubBig standard BedinformationFZPB">
    <div class="h0">
      <p class="lt"></p>
    </div>
    <div class="dRightMain">
      <div
        style="height: 80%"
        class="cardP"
      >
        <el-card class="box-card">
          <div
            slot="header"
            class="clearfix"
          >
            <span>排班信息</span>
            <el-button
              style="float: right; "
              type="success"
              @click="showDialogYS('XZPB')"
            >新增排班
            </el-button>
          </div>
          <div>
            <el-row>

              <el-col :span="6">
                <div class="grid-content bg-purple div_P">
                  <div class="form-group">
                    <p>
                      <label>医院：</label>
                      <select
                        class="form-control"
                        v-model="selectZZJGObj"
                        @change="getDeptListYS()"
                        placeholder="请选择"
                      >
                        <option
                          v-for="(item,index) in zzjgList"
                          :label="item.HospitalName"
                          :value="item"
                          :key="index"
                        ></option>
                      </select>
                    </p>

                  </div>
                </div>
              </el-col>
              <el-col :span="6">
                <div class="grid-content bg-purple div_P">
                  <div class="form-group">
                    <p>
                      <label>科室：</label>
                      <select
                        class="form-control"
                        v-model="selectDeptYS"
                        @change="getUserList"
                        placeholder="请选择"
                      >
                        <option
                          v-for="(item,index) in deptListYS"
                          :label="item.Name"
                          :value="item"
                          :key="index"
                        ></option>
                      </select>
                    </p>
                  </div>
                </div>
              </el-col>
              <el-col :span="6">
                <div class="grid-content bg-purple div_P">
                  <div class="form-group">
                    <p>
                      <label>医生</label>
                      <select
                        class="form-control"
                        v-model="selectDoctor"
                        placeholder="请选择"
                        @change="getHZList"
                      >
                        <option
                          v-for="(item,index) in userList"
                          :label="item.UserName"
                          :value="item"
                          :key="index"
                        ></option>
                      </select>
                    </p>
                  </div>
                </div>
              </el-col>
              <el-col :span="6">
                <div class="grid-content bg-purple div_P">
                  <div class="form-group">
                    <p>
                      <el-button
                        type="primary"
                        @click=" getSZTime()"
                      >上周</el-button>
                      <el-button
                        type="primary"
                        @click=" getBZTime()"
                      >本周</el-button>
                      <el-button type="primary">下周</el-button>
                    </p>
                  </div>
                </div>
              </el-col>
            </el-row>
          </div>
        </el-card>

        <el-table
          :data="tableData"
          height="380"
          style="width: 100%"
        >
          <el-table-column
            fixed="left"
            label="日期"
            width="120"
          >
            <template
              slot-scope="scope"
              class="dateTag"
            >
              <el-tag type="success">
                {{scope.row.ScheduleDate}}<br />{{scope.row.WeekDesc}}</el-tag>

            </template>
          </el-table-column>

          <el-table-column
            label="上午"
            width="480"
          >
            <template slot-scope="scope">
              <el-tag v-for="item in scope.row.SW">
                {{item.DoctorName}}{{item.TimeListStr}}
              </el-tag>

            </template>
          </el-table-column>
          <el-table-column
            label="下午"
            width="480"
          >
            <template slot-scope="scope">
              <el-tag v-for="item in scope.row.XW">
                {{item.DoctorName}}{{item.TimeListStr}}
              </el-tag>

            </template>
          </el-table-column>
          <el-table-column
            label="上午"
            width="480"
          >
            <template slot-scope="scope">
              <el-tag v-for="item in scope.row.WS">
                {{item.DoctorName}}{{item.TimeListStr}}
              </el-tag>

            </template>
          </el-table-column>

          <el-table-column
            v-for="col in cols"
            :prop="col.prop"
            :label="col.label"
            v-if="false"
          >
            <template slot-scope="scope">
              <el-tag>{{scope.row[col.prop]}}</el-tag>
            </template>
          </el-table-column>
        </el-table>

        <el-button
          raw-type="button"
          @click="addCol"
          v-if="false"
        >
          添加一列
        </el-button>

      </div>
    </div>

    <!--弹框添加排班-->
    <div
      class="blackBg hyCZBg"
      v-if="isShowYS=='XZPB'"
    >
      <div class="panel-default column2">
        <em
          class="closes"
          @click="showDialogYS('')"
        >×</em>
        <div class="panel-heading">新增排班</div>
        <div class="pucLabel">
          <el-row>

            <el-col :span="8">
              <div class="grid-content bg-purple div_P">
                <div class="form-group">
                  <p>
                    <label>医院：</label>
                    <select
                      class="form-control"
                      v-model="selectZZJGObjXZ"
                      @change="getDeptListYS()"
                      placeholder="请选择"
                    >
                      <option
                        v-for="(item,index) in zzjgList"
                        :label="item.HospitalName"
                        :value="item"
                        :key="index"
                      ></option>
                    </select>
                  </p>

                </div>
              </div>
            </el-col>
            <el-col :span="8">
              <div class="grid-content bg-purple div_P">
                <div class="form-group">
                  <p>
                    <label>科室：</label>
                    <select
                      class="form-control"
                      v-model="selectDeptYSXZ"
                      @change="getUserListXZ"
                      placeholder="请选择"
                    >
                      <option
                        v-for="(item,index) in deptListYS"
                        :label="item.Name"
                        :value="item"
                        :key="index"
                      ></option>
                    </select>
                  </p>
                </div>
              </div>
            </el-col>
            <el-col :span="8">
              <div class="grid-content bg-purple div_P">
                <div class="form-group">
                  <p>
                    <label>医生</label>
                    <select
                      class="form-control"
                      v-model="selectDoctorXZ"
                      placeholder="请选择"
                    >
                      <option
                        v-for="(item,index) in userListXZ"
                        :label="item.UserName"
                        :value="item"
                        :key="index"
                      ></option>
                    </select>
                  </p>
                </div>
              </div>
            </el-col>

          </el-row>
          <el-row>

            <el-col :span="8">
              <div class="grid-content bg-purple div_P">
                <div class="form-group">
                  <p class="selectTime">
                    <label>起止时间：</label>
                    <el-date-picker
                      style="width: 10rem;height:32px"
                      type="date"
                      value-format="yyyy-MM-dd"
                      v-model="addHZPB.BeginDate"
                      placeholder="选择日期"
                    >
                    </el-date-picker>
                    -
                    <el-date-picker
                      style="width:10rem;height:32px"
                      type="date"
                      value-format="yyyy-MM-dd"
                      v-model="addHZPB.EndDate"
                      placeholder="选择日期"
                    >
                    </el-date-picker>
                  </p>

                </div>
              </div>
            </el-col>
            <el-col :span="16">
              <div class="grid-content bg-purple div_P">
                <div class="form-group">
                  <p>
                    <label>出诊频率：</label>
                    <el-checkbox
                      :indeterminate="isIndeterminate"
                      v-model="checkAll"
                      @change="handleCheckAllChange"
                    >全选
                    </el-checkbox>

                    <el-checkbox-group
                      v-model="checkedCities"
                      @change="handleCheckedCitiesChange"
                    >
                      <el-checkbox
                        v-for="city in cities"
                        :label="city"
                        :key="city"
                      >{{city}}
                      </el-checkbox>
                    </el-checkbox-group>

                  </p>
                </div>
              </div>
            </el-col>
          </el-row>
          <el-row>

            <el-col :span="24">
              <div class="grid-content bg-purple div_P">
                <div class="form-group">
                  <p
                    class="selectTime but"
                    v-for="(item,i) in addHZPB.TimeLst"
                  >
                    <label>接诊时间：</label>
                    <el-time-select
                      style="width:10rem;height:32px"
                      v-model="item.Stime"
                      :picker-options="{    start: '07:30',    step: '00:15',    end: '19:30'  }"
                      placeholder="选择时间"
                    >
                    </el-time-select>
                    -
                    <el-time-select
                      style="width:10rem;height:32px"
                      v-model="item.ETime"
                      :picker-options="{    start: '07:30',    step: '00:15',    end: '19:30'  }"
                      placeholder="选择时间"
                    >
                    </el-time-select>
                    <el-button
                      type="danger"
                      icon="el-icon-close"
                      circle
                      @click="DialogremoveTime(i)"
                    ></el-button>
                  </p>
                  <p class="selectTime but">
                    <el-button
                      type="primary"
                      icon="el-icon-plus"
                      circle
                      @click="DialogAddTime()"
                    ></el-button>
                  </p>
                </div>
              </div>
            </el-col>

          </el-row>
        </div>
        <div class="modal-footer">
          <button
            type="button"
            class="btn btn-default"
            @click="addHZPB2Http()"
          >确定</button>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
const cityOptions = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日'];
export default {
  name: "BedinformationFZ",
  data () {
    return {
      msg: "SystemManagement 下的 Bedinformation",
      isShow: "",
      isShowYS: "",
      /*****************************会诊医生排班*************************************/
      zzjgList: [],
      deptList: [],
      LoginInfor: {},
      deptListYS: [],
      userList: [],
      selectDoctor: {},
      selectDept: {},
      selectDeptYS: {},
      selectZZJGObj: {},

      tableData: [],
      cols: [
        // {prop: 'date', label: '日期'},
      ],
      /***新增排班**/
      selectDoctorXZ: {},
      selectDeptXZ: {},
      selectDeptYSXZ: {},
      selectZZJGObjXZ: {},
      userListXZ: [],
      Time: "",
      JZSC: [{ name: "15分钟" }, { name: "30分钟" }],
      addHZPB: {
        Id: 0,
        HospitalId: 0,
        DeptId: 0,
        DoctorId: 0,
        ConsultRoomId: 0,
        BeginDate: "",
        EndDate: "",
        TimeRange: "",

        WeekList: "",
        TimeLst: [{ Stime: "", ETime: "" }]
      },
      getHZPBObj: {
        bdate: "",
        edate: "",
        HospitalId: "-1",
        DeptId: "-1",
        DoctorId: "-1",
      },
      /***周**/
      checkAll: false,
      checkedCities: [],
      cities: cityOptions,
      isIndeterminate: true
    };
  },
  methods: {
    showDialog (show) {
      this.isShow = show;
      if (show == "") {
        this.selectHZInfor = null;
        // this.isShowYS = "";
      }
    },
    showDialogYS (show) {
      this.isShowYS = show;
    },
    DialogAddTime () {
      var Time = {
        Stime: "", ETime: ""
      }
      this.addHZPB.TimeLst.push(Time);
    },
    DialogremoveTime (index) {

      this.addHZPB.TimeLst.splice(index, 1);
    },
    /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&会诊医生排班开始&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
    getZZJGList () {
      this.zzjgList = [];
      var params = {
        name: ""
      };
      this.$get("Hospital/GetList", params)
        .then(res => {
          //this.total = res.data.totalCount;//
          this.zzjgList = res.data;
          if (this.zzjgList.length > 0) {
            this.selectZZJGObj = this.zzjgList[0];
            this.getDeptListYS();
          }
          console.log("组织机构列表查询结果");
          console.log(res);
        })
        .catch(err => {
          console.log(err);
        });
    },
    getDeptListYS () {
      //
      var params = {
        HospitalId: this.selectZZJGObj.HospitalId,
        name: ""
      };
      this.$get("Dept/GetList", params)
        .then(res => {
          this.deptListYS = res.data;
          console.log("科室列表查询结果");
          console.log(res);
        })
        .catch(err => {
          console.log(err);
        });
    },
    getUserList () {
      this.userList = [];

      if (this.selectZZJGObj == null) {
        this.$message({
          showClose: true,
          message: "请选择操作机构！",
          type: "error"
        });
        return;
      }
      var params = {
        HospitalId: this.selectZZJGObj.HospitalId,
        SectionId: this.selectDeptYS.Id
      };
      this.$get("User/GetListBySection", params)
        .then(res => {
          this.userList = res.data;
          console.log("用户列表查询结果");
          console.log(res);
        })
        .catch(err => {
          console.log(err);
        });
    },
    getUserListXZ () {
      this.userListXZ = [];

      if (this.selectZZJGObjXZ == null) {
        this.$message({
          showClose: true,
          message: "请选择操作机构！",
          type: "error"
        });
        return;
      }
      var params = {
        HospitalId: this.selectZZJGObjXZ.HospitalId,
        SectionId: this.selectDeptYSXZ.Id
      };
      this.$get("User/GetListBySection", params)
        .then(res => {
          this.userListXZ = res.data;
          console.log("用户列表查询结果");
          console.log(res);
        })
        .catch(err => {
          console.log(err);
        });
    },
    addCol () {
      for (var i = 0; i < this.tableData.length; i++) {
        for (var j = 0; j < this.tableData[i].timeList.length; j++) {
          var timeName = this.tableData[i].timeList[j].time
          var count = this.tableData[i].timeList[j].count
          var vars = {}; //批量定义
          var varName = timeName;  //动态定义变量名
          this.tableData[i][varName] = count;  //动态赋值
        }
      }
      console.log("排班数据调整完成");
      console.log(this.tableData);
      for (var j = 0; j < this.tableData[0].timeList.length; j++) {
        var timeName = this.tableData[0].timeList[j].time
        this.setCol(timeName)
      }
    },
    setCol (label) {
      this.cols.push({ prop: label, label: label })
    },
    addHZPB2Http () {
      if (this.selectDoctorXZ == null) {
        this.$message({
          showClose: true,
          message: "请选择医生！",
          type: "error"
        });
        return;
      }
      this.addHZPB.HospitalId = this.selectZZJGObjXZ.HospitalId;
      this.addHZPB.DeptId = this.selectDeptYSXZ.Id;
      this.addHZPB.DoctorId = this.selectDoctorXZ.UserId;
      var TimeStr = '';
      for (var i = 0; i < this.addHZPB.TimeLst.length; i++) {
        if (i == (this.addHZPB.TimeLst.length - 1)) {
          TimeStr += this.addHZPB.TimeLst[i].Stime + '^' + this.addHZPB.TimeLst[i].ETime;
        } else {
          TimeStr += this.addHZPB.TimeLst[i].Stime + '^' + this.addHZPB.TimeLst[i].ETime + '#';
        }
      }
      console.log("时间段拼接")
      console.log(TimeStr);

      this.addHZPB.TimeRange = TimeStr;
      var weekStr = this.checkedCities.toLocaleString();
      console.log(weekStr)
      this.addHZPB.WeekList = weekStr;
      this.addHZPB.TimeLst = [];
      var params = this.addHZPB;
      //POST /api/ConsultScheduling/addScheduleList
      this.$post("ConsultScheduling/addScheduleList", params)
        .then(res => {
          console.log("添加会诊排班结果");
          console.log(res);
          if (res.code == 0) {

          } else {
            this.$message({
              showClose: true,
              message: res.msg,
              type: "error"
            });
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    getHZPBList (bdate, edate) {
      if (this.selectDeptYS == null) {
        this.$message({
          showClose: true,
          message: "请选择科室！",
          type: "error"
        });
        return;
      }
      this.getHZPBObj.HospitalId = this.selectZZJGObj.HospitalId;
      this.getHZPBObj.DeptId = this.selectDeptYS.Id;
      if (this.selectDoctor != null && this.selectDoctor.UserId != null && this.selectDoctor.UserId != "") {
        this.getHZPBObj.DoctorId = this.selectDoctor.UserId;
      }
      this.getHZPBObj.bdate = bdate
      this.getHZPBObj.edate = edate;
      var params = this.getHZPBObj;
      // GET /api/ConsultScheduling/GetList
      this.$get("ConsultScheduling/GetList", params)
        .then(res => {
          // console.log("会诊排班列表查询结果");
          // console.log(res);
          this.tableData = res.data;
          for (var i = 0; i < this.tableData.length; i++) {
            for (var j = 0; j < this.tableData[i].DayDetail.length; j++) {
              if (this.tableData[i].DayDetail[j].TimeFlag == "上午") {
                for (var k = 0; k < this.tableData[i].DayDetail[j].DoctorDetail.length; k++) {
                  var objItem = this.tableData[i].DayDetail[j].DoctorDetail[k];
                  var TimeListStr = '';
                  for (var n = 0; n < objItem.TimeList.length; n++) {
                    TimeListStr += objItem.TimeList[n].BeginTime + "-" + objItem.TimeList[n].EndTime + "# "
                  }
                  var SWObj = {
                    ConsultRoomId: objItem.ConsultRoomId,
                    ConsultRoomName: objItem.ConsultRoomName,
                    DeptId: objItem.DeptId,
                    DeptName: objItem.DeptName,
                    DoctorId: objItem.DoctorId,
                    DoctorName: objItem.DoctorName,
                    HospitalId: objItem.HospitalId,
                    HospitalName: objItem.HospitalName,
                    TimeList: objItem.TimeList,
                    TimeListStr: TimeListStr
                  }
                  this.tableData[i].SW = [];
                  this.tableData[i].SW.push(SWObj)
                }

              }
              else if (this.tableData[i].DayDetail[j].TimeFlag == "下午") {
                for (var k = 0; k < this.tableData[i].DayDetail[j].DoctorDetail.length; k++) {
                  var objItem = this.tableData[i].DayDetail[j].DoctorDetail[k];
                  var TimeListStr = '';
                  for (var n = 0; n < objItem.TimeList.length; n++) {
                    TimeListStr += objItem.TimeList[n].BeginTime + "-" + objItem.TimeList[n].EndTime + "# "
                  }
                  var SWObj = {
                    ConsultRoomId: objItem.ConsultRoomId,
                    ConsultRoomName: objItem.ConsultRoomName,
                    DeptId: objItem.DeptId,
                    DeptName: objItem.DeptName,
                    DoctorId: objItem.DoctorId,
                    DoctorName: objItem.DoctorName,
                    HospitalId: objItem.HospitalId,
                    HospitalName: objItem.HospitalName,
                    TimeListStr: TimeListStr
                  }
                  this.tableData[i].XW = [];
                  this.tableData[i].XW.push(SWObj)
                }

              }
              else if (this.tableData[i].DayDetail[j].TimeFlag == "晚上") {
                for (var k = 0; k < this.tableData[i].DayDetail[j].DoctorDetail.length; k++) {
                  var objItem = this.tableData[i].DayDetail[j].DoctorDetail[k];
                  var TimeListStr = '';
                  for (var n = 0; n < objItem.TimeList.length; n++) {
                    TimeListStr += objItem.TimeList[n].BeginTime + "-" + objItem.TimeList[n].EndTime + "# "
                  }
                  var SWObj = {
                    ConsultRoomId: objItem.ConsultRoomId,
                    ConsultRoomName: objItem.ConsultRoomName,
                    DeptId: objItem.DeptId,
                    DeptName: objItem.DeptName,
                    DoctorId: objItem.DoctorId,
                    DoctorName: objItem.DoctorName,
                    HospitalId: objItem.HospitalId,
                    HospitalName: objItem.HospitalName,
                    TimeListStr: TimeListStr
                  }
                  this.tableData[i].WS = [];
                  this.tableData[i].WS.push(SWObj)
                }

              }
            }

          }
          console.log("数据调整完成")
          console.log(this.tableData)
        })
        .catch(err => {
          console.log(err);
        });
    },
    handleCheckAllChange (val) {
      this.checkedCities = val ? cityOptions : [];
      this.isIndeterminate = false;
    },
    handleCheckedCitiesChange (value) {
      let checkedCount = value.length;
      this.checkAll = checkedCount === this.cities.length;
      this.isIndeterminate = checkedCount > 0 && checkedCount < this.cities.length;
    },
    /****************************************************************/
    //本周
    getBZTime () {
      console.log("本周的开始时间");
      //本周的开始时间
      console.log(this.getTime(0));
      //本周的结束时间
      console.log(this.getTime(-6));
      var bdate = this.getTime(0)
      var edate = this.getTime(-6)
      console.log("本周排班数据获取");
      this.getHZPBList(bdate, edate)
    },
    getSZTime () {
      console.log("上周的开始时间");
      //上周的开始时间
      console.log(this.getTime(7));
      //上周的结束时间
      console.log(this.getTime(1));
      var bdate = this.getTime(7)
      var edate = this.getTime(1)
      this.getHZPBList(bdate, edate)
    },

    getTime (n) {
      var now = new Date();
      var year = now.getFullYear();
      //因为月份是从0开始的,所以获取这个月的月份数要加1才行
      var month = now.getMonth() + 1;
      var date = now.getDate();
      var day = now.getDay();
      console.log(date);
      //判断是否为周日,如果不是的话,就让今天的day-1(例如星期二就是2-1)
      if (day !== 0) {
        n = n + (day - 1);
      } else {
        n = n + day;
      }
      if (day) {
        //这个判断是为了解决跨年的问题
        if (month > 1) {
          month = month;
        }
        //这个判断是为了解决跨年的问题,月份是从0开始的
        else {
          year = year - 1;
          month = 12;
        }
      }
      now.setDate(now.getDate() - n);
      year = now.getFullYear();
      month = now.getMonth() + 1;
      date = now.getDate();
      console.log(n);
      var s = year + "-" + (month < 10 ? ('0' + month) : month) + "-" + (date < 10 ? ('0' + date) : date) + "";
      return s;
    },
    /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&会诊医生排班结束&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
    handleClickInforItem (row) {
      console.log("查看详情操作");
      console.log(row);
      this.getHZInfor(row.Id)
      this.selectHZInfor = row;
      this.getHZBGList();
    },
    handleClick (tab, event) {
      console.log(tab, event);
      this.getHZList();
    },
    handleCurrentChange (val) {
      console.log(`当前页: ${val}`);
      this.getHZListObj.page = val;
      this.getHZList()
    },
    getHZList () {
      this.huizhenList = [];
      var params = this.getHZListObj;
      this.$get("ConsultBuss/GetList", params)
        .then(res => {
          console.log("会诊列表查询结果");
          console.log(res);
          this.total = res.data.TotalCount;
          this.huizhenList = res.data.list[0].Table;
          for (var i = 0; i < this.huizhenList.length; i++) {
            if (this.huizhenList[i].Status == 0) {
              this.huizhenList[i].StatusName = '申请'
            } else if (this.huizhenList[i].Status == 1) {
              this.huizhenList[i].StatusName = '提交'
            } else if (this.huizhenList[i].Status == 2) {
              this.huizhenList[i].StatusName = '前质控'
            } else if (this.huizhenList[i].Status == 3) {
              this.huizhenList[i].StatusName = '分诊'
            } else if (this.huizhenList[i].Status == 4) {
              this.huizhenList[i].StatusName = '报告'
            } else if (this.huizhenList[i].Status == 5) {
              this.huizhenList[i].StatusName = '审核'
            } else if (this.huizhenList[i].Status == 6) {
              this.huizhenList[i].StatusName = '后质控'
            } else if (this.huizhenList[i].Status == 7) {
              this.huizhenList[i].StatusName = '完成'
            }

          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    getHZInfor (ConsultId) {

      var params = {
        ConsultId: ConsultId
      };
      this.$get("ConsultBuss/Get", params)
        .then(res => {
          console.log("会诊明细查询结果");
          console.log(res);
          if (res.code == 0) {
            this.huizhenObj = res.data;
            this.showDialog('Infor')
            console.log(this.LoginInfor.UserId);
            for (var i = 0; i < this.huizhenObj.Consult_Joins.length; i++) {
              console.log(this.huizhenObj.Consult_Joins[i].DoctorId)
              console.log(this.huizhenObj.Consult_Joins[i].IsMaster)
              if (this.huizhenObj.Consult_Joins[i].DoctorId == this.LoginInfor.UserId && this.huizhenObj.Consult_Joins[i].IsMaster == 1) {
                this.isZZ = "OK"
                console.log("主诊本登录账号")
              }
            }
          }

        })
        .catch(err => {
          console.log(err);
        });
    },
    addHZBG () {
      if (this.selectHZInfor == null) {
        this.$message({
          showClose: true,
          message: "请选择会诊明细！",
          type: "error"
        });
        return;
      }
      this.HZBGObj.ConsultId = this.selectHZInfor.Id;
      this.HZBGObj.ReportUserId = this.LoginInfor.UserId;
      var params = this.HZBGObj;
      //POST /api/ConsultReport/Create
      this.$post("ConsultReport/Create", params)
        .then(res => {
          console.log("添加会诊报告结果");
          console.log(res);
          if (res.code == 0) {
            this.getHZBGList();
            if (this.isZZ == 'OK') {
              this.finishHZ(3);
              this.finishHZ(4);
            }
          } else {
            this.$message({
              showClose: true,
              message: "会诊报告添加失败！",
              type: "error"
            });
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    getHZBGList () {
      this.HZBGList = [];
      if (this.selectHZInfor == null) {
        this.$message({
          showClose: true,
          message: "请选择会诊明细！",
          type: "error"
        });
        return;
      }
      var params = {
        ConsultId: this.selectHZInfor.Id
      };
      this.$get("ConsultReport/GetList", params)
        .then(res => {
          console.log("会诊报告列表查询结果");
          console.log(res);
          this.HZBGList = res.data;
        })
        .catch(err => {
          console.log(err);
        });
    },
    finishHZ (Status) {
      if (this.selectHZInfor == null) {
        this.$message({
          showClose: true,
          message: "请选择会诊数据！",
          type: "error"
        });
        return;
      }
      var params = {
        ConsultId: this.selectHZInfor.Id,
        Status: Status
      };
      //POST /api/ConsultBuss/ChangeConsultStatus
      this.$post("ConsultBuss/ChangeConsultStatus", params)
        .then(res => {
          console.log("结束会诊结果");
          console.log(res);
          if (res.code == 0) {
            this.getHZList();
            if (Status == 1) {
              this.showDialog('')
              this.getHZInfor(this.selectHZInfor.Id)
            }
          } else {
            this.$message({
              showClose: true,
              message: "申请会诊结束失败！",
              type: "error"
            });
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    handleClickPICItem (row) {
      console.log(row);
      this.imgSrcUrl = this.$getBaseIP() + row.FilePath;
      console.log("图片路径")
      console.log(this.imgSrcUrl)
      this.showDialog("PIC");
    },
    addHZVideo () {
      if (this.isZZ == 'OK') {
        this.finishHZ(2);
      }
      if (this.selectHZInfor == null) {
        this.$message({
          showClose: true,
          message: "请选择会诊明细！",
          type: "error"
        });
        return;
      }
      var params = {
        ConsultId: this.selectHZInfor.Id
      };
      this.$get("ConsultBuss/GetVideoUrl", params)
        .then(res => {
          console.log("会诊视频地址查询结果");
          console.log(res);
          // this.LoginInfor.UserName = "张珊"
          // var roomUrl = "https://121.43.170.162/webapp/conference/663800?name=" + this.LoginInfor.UserName + "&role=host"
          if (res.code == 0) {
            console.log("执行加入会议跳转")
            window.open(res.data, "_blank");
          }

        })
        .catch(err => {
          console.log(err);
        });


    },


    /***************分诊医生操作**************************/

    selectYSChange (val, column, event) {
      console.log("选中会诊医生数据");
      console.log(val)
      var Consult_Join = {
        Id: -1,
        ConsultId: this.huizhenObj.Consult.Id,
        DeptKind: 0,
        HospitalId: val.HospitalId,
        DeptId: this.selectDeptYS.Id,
        DoctorId: val.UserId,
        Doctor: val.UserName,
        UserName: val.UserName,
        Title: val.Title,
        Describe: val.Describe,
        ConRoomId: -1,
        isCanWrite: 0,
        IsMaster: 0,
        joinTime: "2020-01-14T02:09:31.447Z",
        JoinId: 0
      }

      this.huizhenObj.Consult_Joins.push(Consult_Join)
      this.addFZYS(Consult_Join)
      this.showDialogYS('')
    },
    /******************************添加分诊医生****************************************/
    addFZYS (params) {
      console.log("添加会诊分诊信息")
      console.log(params);
      //POST /api/ConsultJoin/Create
      this.$post("ConsultJoin/Create", params)
        .then(res => {
          console.log("添加会诊分诊医生");
          console.log(res);
          if (res.code == 0) {
            this.getHZInfor(params.ConsultId)
          } else {
            this.$message({
              showClose: true,
              message: "会诊分诊医生添加失败",
              type: "error"
            });
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    deleteFZYS (Id, ConsultId) {
      var patams = {
        Id: Id
      }
      //POST /api/ConsultJoin/Delete
      this.$post("ConsultJoin/Delete", patams)
        .then(res => {
          console.log("删除会诊分诊医生结果");
          console.log(res);
          if (res.code == 0) {
            console.log("会诊明细ID");
            console.log(ConsultId)
            this.getHZInfor(ConsultId)
          } else {
            this.$message({
              showClose: true,
              message: "会诊分诊医生添加失败",
              type: "error"
            });
          }
        })
        .catch(err => {
          console.log(err);
        });
    },

    updateFZYS (patams) {
      //POST /api/ConsultJoin/Update
      this.$post("ConsultJoin/Update", patams)
        .then(res => {
          console.log("更新会诊分诊医生结果");
          console.log(res);
          if (res.code == 0) {

          } else {
            this.$message({
              showClose: true,
              message: "会诊分诊医生更新失败",
              type: "error"
            });
          }
        })
        .catch(err => {
          console.log(err);
        });
    },

    updateRow2YS (index, rows) {
      console.log("是否主诊");
      console.log(index);
      var rowItem = rows[index];
      rows.forEach(m => {
        if (m.DoctorId == rowItem.DoctorId) {
          if (m.IsMaster == 0) {
            m.IsMaster = 1;
          } else {
            m.IsMaster = 0;
          }
        } else {
          m.IsMaster = 0;
        }
        this.updateFZYS(m)
      })

      console.log("会诊明细ID");
      console.log(rows[0].ConsultId)
      this.getHZInfor(rows[0].ConsultId)
    },
    deleteRow2YS (index, rows) {
      console.log("删除医生操作");
      console.log(index);
      // rows.splice(index, 1);
      console.log(rows[index]);
      this.deleteFZYS(rows[index].Id, rows[index].ConsultId);
    },
    //17340 //20471

    /*****************************会诊详情框*******************************************************/
    handleClickJCItem (row) {
      console.log("查看检查操作");
      console.log(row);
      this.$scanOpenJC("PACS", row.StudyId, this.getMsg)
    },
    handleClickBLItem (row) {
      console.log("查看病理操作");
      console.log(row);
      this.$scanOpenJC("US", row.StudyId, this.getMsg)
    },
    handleClickXDItem (row) {
      console.log("查看心电操作");
      console.log(row);
      this.$scanOpenJC("ECG", row.StudyId, this.getMsg)
    },
  },
  created () {
    if (this.$route.query.Token) {
      localStorage.setItem('Token', this.$route.query.Token)
    }
    this.getZZJGList();
    this.getHZList();
  }
};
</script>
<style lang="scss">
.BedinformationFZPB {
  .selectTime {
    .el-input__icon {
      height: 100%;
      width: 25px;
      display: none;
      text-align: center;
      -webkit-transition: all 0.3s;
      transition: all 0.3s;
      line-height: 40px;
    }

    .input {
      width: 90px !important;
      height: 28px !important;
    }
  }
  .dateTag {
    .el-tag {
      background-color: #ecf5ff;
      border-color: #d9ecff;
      display: inline-block;
      height: 69px !important;
      padding: 0 10px;
      line-height: 32px !important;
      font-size: 12px;
      color: #409eff;
      border-width: 1px;
      border-style: solid;
      border-radius: 4px;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
      white-space: nowrap;
    }
  }
  .but {
    .el-button.is-circle {
      border-radius: 50%;
      padding: 4px !important;
    }
  }

  .column2 {
    width: 1126px;
    margin: 50px auto;
    background: #fff;
    border-radius: 5px;
    position: relative;
  }

  .div_P {
    .form-control {
      display: inline-block;
      width: 180px;
      height: 32px;
      padding: 5px 12px;
      font-size: 14px;
      line-height: 1.42857143;
      color: #555;
      background-color: #fff;
      background-image: none;
      border: 1px solid #ccc;
      border-radius: 4px;
      -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
      box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
      -webkit-transition: border-color ease-in-out 0.15s,
        -webkit-box-shadow ease-in-out 0.15s;
      transition: border-color ease-in-out 0.15s,
        -webkit-box-shadow ease-in-out 0.15s;
      transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s;
      transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s,
        -webkit-box-shadow ease-in-out 0.15s;
    }

    .form-group {
      height: 45px;
      margin: 0;
      line-height: 32px;
      padding: 6px 15px 0 15px;
    }
  }

  .fjtable {
    .el-table {
      font-size: 10px !important;
    }
  }

  .cardP {
    .text {
      font-size: 14px;
    }

    .el-card__header {
      padding: 18px 20px;
      border-bottom: 1px solid #ebeef5;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
      background-color: azure;
    }

    .item {
      margin-bottom: 18px;
    }

    .clearfix:before,
    .clearfix:after {
      display: table;
      content: "";
    }

    .clearfix:after {
      clear: both;
    }

    .box-card {
      width: 100%;
    }
  }

  .cardC {
    .text {
      font-size: 14px;
    }

    .el-card__header {
      padding: 10px 20px;
      border-bottom: 1px solid #ebeef5;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
      background-color: white;
    }

    .el-card__body {
      padding: 8px;
    }

    .item {
      margin-bottom: 18px;
    }

    .clearfix:before,
    .clearfix:after {
      display: table;
      content: "";
    }

    .clearfix:after {
      clear: both;
    }

    .box-card {
      width: 100%;
    }
  }

  .el-tree-node.is-current > .el-tree-node__content {
    color: #fff;
    background: #155a00 !important;
  }

  .dRightMain {
    padding: 18px;
  }

  .custom-tree-node {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    padding-right: 8px;
  }

  .el-table {
    font-size: 14px !important;
  }

  .el-table thead {
    color: #303133;
  }

  .dRightMain .Tb {
    position: absolute;
    top: 91px;
    left: 240px;
    right: 15px;
    bottom: 0;
    border: 1px solid #ddd;
  }
}

.InspectionCL22 {
  .selectTime {
    .el-input__icon {
      height: 100%;
      width: 25px;
      display: none;
      text-align: center;
      -webkit-transition: all 0.3s;
      transition: all 0.3s;
      line-height: 40px;
    }

    .input {
      width: 90px !important;
      height: 28px !important;
    }
  }

  .form-control {
    width: 106px !important;
  }

  .div_P {
    .form-control {
      display: inline-block;
      width: 180px;
      height: 32px;
      padding: 5px 12px;
      font-size: 14px;
      line-height: 1.42857143;
      color: #555;
      background-color: #fff;
      background-image: none;
      border: 1px solid #ccc;
      border-radius: 4px;
      -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
      box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
      -webkit-transition: border-color ease-in-out 0.15s,
        -webkit-box-shadow ease-in-out 0.15s;
      transition: border-color ease-in-out 0.15s,
        -webkit-box-shadow ease-in-out 0.15s;
      transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s;
      transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s,
        -webkit-box-shadow ease-in-out 0.15s;
    }

    .form-group {
      height: 45px;
      margin: 0;
      line-height: 32px;
      padding: 6px 15px 0 15px;
    }
  }

  .fjtable {
    .el-table {
      font-size: 10px !important;
    }
  }

  .cardP {
    .text {
      font-size: 14px;
    }

    .el-card__header {
      padding: 18px 20px;
      border-bottom: 1px solid #ebeef5;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
      background-color: azure;
    }

    .item {
      margin-bottom: 18px;
    }

    .clearfix:before,
    .clearfix:after {
      display: table;
      content: "";
    }

    .clearfix:after {
      clear: both;
    }

    .box-card {
      width: 100%;
    }
  }

  .cardC {
    .text {
      font-size: 14px;
    }

    .el-card__header {
      padding: 10px 20px;
      border-bottom: 1px solid #ebeef5;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
      background-color: white;
    }

    .el-card__body {
      padding: 8px;
    }

    .item {
      margin-bottom: 18px;
    }

    .clearfix:before,
    .clearfix:after {
      display: table;
      content: "";
    }

    .clearfix:after {
      clear: both;
    }

    .box-card {
      width: 100%;
    }
  }

  .el-tree-node.is-current > .el-tree-node__content {
    color: #fff;
    background: #155a00 !important;
  }

  .dRightMain {
    padding: 18px;
  }

  .custom-tree-node {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    padding-right: 8px;
  }

  .el-table {
    font-size: 14px !important;
  }

  .el-table thead {
    color: #303133;
  }

  .dRightMain .Tb {
    position: absolute;
    top: 91px;
    left: 240px;
    right: 15px;
    bottom: 0;
    border: 1px solid #ddd;
  }
}
</style>
